<extend name="Public:base" />
<block name="title">修改密码</block>
<block name="content">
    <form action="" method="post" id="ajaxForm">
        <div class="page__bd">
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">旧密码</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="password" id="oldpass" name="oldpass" placeholder="请输入原密码">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">新密码</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="password" id="newpass1" name="newpass" placeholder="请输入密码">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">确认密码</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="password" id="newpass2" placeholder="请输入确认密码">
                </div>
            </div>
            <div class="button-sp-area xiugai_but_area">
                <a href="__MODULE__/User/userlist" class="weui-btn weui-btn_mini weui-btn_default">返回</a>
                <a href="javascript:;" id="passmod" class="weui-btn weui-btn_mini weui-btn_primary">修改</a>
            </div>
        </div>
    </form>
    <script type="text/javascript">
        $(document).on('click','#passmod',function(){
            var oldpass     = $('#oldpass').val();
            var newpass1    = $('#newpass1').val();
            var newpass2    = $('#newpass2').val();
            if(oldpass == ''){
                layer.msg('请填写旧密码！');
                return false;
            }
            if(newpass1 == '' || newpass1.length < 6){
                layer.msg('请填写新密码，不能少于6个字符！');
                return false;
            }
            if(newpass2 == '' || newpass2.length < 6){
                layer.msg('请填写确认新密码！，不能少于6个字符！');
                return false;
            }
            if(newpass1 != newpass2){
                layer.msg('两次输入的密码不一致！');
                return false;
            }
            var formData = $('#ajaxForm').serialize();
            $.ajax({
                type:'post',
                url:'__MODULE__/User/passmod',
                data:formData,
                cache:false,
                dataType:'json',
                success:function(res){
                    if(res.code == 0){
                        layer.msg(res.msg,function () {
                            window.location.href = res.url;
                        });
                        return false;
                    }else{
                        layer.msg(res.msg);
                        return false;
                    }
                }
            });
        });
    </script>
</block>